﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SqlCon;

namespace yfxt
{
    public partial class gl_ypsld_you : Form
    {
        public gl_ypsld_you()
        {
            InitializeComponent();
        }

        private void gl_ypsld_you_Load(object sender, EventArgs e)
        {
            dataGridView1.AllowUserToResizeRows = false;                     //禁止用鼠标调整datagridView单元格的大小。
            dataGridView1.AllowUserToResizeColumns = false;
            foreach (DataGridViewColumn c in dataGridView1.Columns)        //禁止对datagridView列进行排序
            {
                c.SortMode = DataGridViewColumnSortMode.NotSortable;
            }

            string lingyaodanhao = ((gl_ypsl)this.Owner).lingyaodanhao;
            DataTable dt = new DataTable();
            DataTable dt2 = new DataTable();

            //显示No.100001
            label6.Text = lingyaodanhao;

            //显示确认日期、备注、领药员lygh、确认员qrgh、领用药房
            string comStr = "select t.lyrq,t.ckbz,t1.ygxm,t2.ygxm,t3.yfmc from Yk_cK01 t,GY_YGDM t1,GY_YGDM t2,yf_yflb t3 where t.ckdh='" + lingyaodanhao + "' " +
                "and t.czgh=t1.ygbh and t.lygh=t2.ygbh and t.yfsb=t3.yfsb";
            dt2.Load(SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, comStr, null));
            textBox2.Text = Convert.ToDateTime(dt2.Rows[0][0]).ToString("yyyy-MM-dd").Replace('-', '.');
            textBox3.Text = dt2.Rows[0][1].ToString();
            textBox4.Text = dt2.Rows[0][2].ToString();
            textBox5.Text = dt2.Rows[0][3].ToString();
            textBox1.Text = dt2.Rows[0][4].ToString();

            //显示合计
            comStr = "select sum(lsje) from Yk_cK02 where ckdh='" + lingyaodanhao + "'";
            string total_lsje = (SqlHelper.ExecuteScalar(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, comStr, null)).ToString();
            textBox6.Text = total_lsje;

            //显示datagridView1的
            comStr = "select t1.ypmc,t1.yfgg,t1.yfdw,t2.cdqc,t.lsje,t.sqsl,t.sfsl,t.lsjg from Yk_cK02 t,yk_typk t1,YK_CDDZ t2 " +
                "where t.ckdh='" + lingyaodanhao + "' and t.ypxh=t1.ypxh and t2.ypcd=t.ypcd";
            dt.Load(SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, comStr, null));

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                dataGridView1.Rows.Add(1);

                for (int j = 0; j < 8; j++)
                {
                    if (dt.Rows[i][j].ToString() != "")
                    {
                        
                        dataGridView1.Rows[i].Cells[j].Value = dt.Rows[i][j].ToString();
                    }
                }
            }
            //string lingyaodanhao = ((gl_ypsl)this.Owner).lingyaodanhao;
            //DataTable dt = new DataTable();
            //DataTable dt2 = new DataTable();
            //DataTable dt3 = new DataTable();

            ////显示No.100001
            //label6.Text = lingyaodanhao;

            ////确认日期、备注
            //string comStr = "select sqrq,ckbz,czgh,lygh from Yk_cK01 where ckdh='" + lingyaodanhao + "'";
            //dt2.Load(SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, comStr, null));
            //textBox2.Text = Convert.ToDateTime(dt2.Rows[0][0]).ToString("yyyy-MM-dd").Replace('-', '.');
            //textBox3.Text = dt2.Rows[0][1].ToString();

            ////显示领药人、确认人
            //comStr = "select ygxm from GY_YGDM where ygbh='" + dt2.Rows[0][2].ToString() + "'";
            //string ygxm = (SqlHelper.ExecuteScalar(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, comStr, null)).ToString();
            //textBox4.Text = ygxm;
            //comStr = "select ygxm from GY_YGDM where ygbh='" + dt2.Rows[0][3].ToString() + "'";
            //string ygxm2 = (SqlHelper.ExecuteScalar(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, comStr, null)).ToString();
            //textBox4.Text = ygxm2;

            ////显示datagridView1的
            //#region
            //comStr = "select ypxh,ypcd,lsjg,SQSL,SFSL from Yk_cK02 where ckdh='" + lingyaodanhao + "'";
            //dt.Load(SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, comStr, null));
            //for (int i = 0; i < dt.Rows.Count; i++)
            //{
            //    dataGridView1.Rows.Add(1);

            //    //显示药品名称、药品规格、药品单位
            //    //if (mainform.yfsb == 3)                  //3表示中心药房
            //    //{
            //        comStr = "select ypmc,BFGG,BFDW from yk_typk where ypxh='" + dt.Rows[i][0].ToString() + "'";
            //        dt3.Load(SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, comStr, null));
            //        dataGridView1.Rows[i].Cells[0].Value = dt3.Rows[i][0].ToString();
            //        dataGridView1.Rows[i].Cells[1].Value = dt3.Rows[i][1].ToString();
            //        dataGridView1.Rows[i].Cells[2].Value = dt3.Rows[i][2].ToString();
            //    //}
            //    //else
            //    //{
            //    //    comStr = "select ypmc,YFGG,YFDW from yk_typk where ypxh='" + dt.Rows[i][0].ToString() + "'";
            //    //    dt3.Load(SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, comStr, null));
            //    //    dataGridView1.Rows[i].Cells[0].Value = dt3.Rows[i][0].ToString();
            //    //    dataGridView1.Rows[i].Cells[1].Value = dt3.Rows[i][1].ToString();
            //    //    dataGridView1.Rows[i].Cells[2].Value = dt3.Rows[i][2].ToString();
            //    //}

            //    for (int j = 3; j < 7; j++)
            //    {
            //        if (j != 3)
            //        {
            //            dataGridView1.Rows[i].Cells[j].Value = dt.Rows[i][j - 2].ToString();
            //        }
            //        else
            //        {
            //            //显示产地
            //            comStr = "select cdqc from YK_CDDZ where ypcd='" + dt.Rows[i][1].ToString() + "'";
            //            string cdqc = (SqlHelper.ExecuteScalar(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, comStr, null)).ToString();
            //            dataGridView1.Rows[i].Cells[3].Value = cdqc;
            //        }
            //    }
            //}
            //#endregion

            ////显示领用药房
            //comStr = "select yfmc from Yf_YfLB where yfsb='" + mainform.yfsb + "'";
            //string yfmc = (SqlHelper.ExecuteScalar(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, comStr, null)).ToString();
            //textBox1.Text = yfmc;

            ////显示合计
            //comStr = "select sum(lsjg*SQSL) from Yk_cK02 where ckdh='" + lingyaodanhao + "'";
            //decimal total_lsje = decimal.Parse((SqlHelper.ExecuteScalar(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, comStr, null)).ToString());
            //textBox6.Text = total_lsje.ToString("F4");
        }

        #region 退出按钮
        private void button4_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        #endregion
    }
}
